# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html
import scrapy
from scrapy.pipelines.images import ImagesPipeline
# useful for handling different item types with a single interface


class TopicdetailPipeline(ImagesPipeline):

    # IMAGES_STORE = get_project_settings().get('IMAGES_STORE')
    def file_path(self, request, response=None, info=None):
        imagename = request.url.split('/')[-1]
        return imagename

    def get_media_requests(self, item, info):
        """
        下载
        :param item:
        :param info:
        :return:
        """
        yield scrapy.Request(item['image_url'], meta={'item': item})

    def item_completed(self, results, item, info):
        print("下载图片结果：" + str(results))
        return item
